package com.baize.minespace.controller;


import com.baize.minespace.pojo.PostCategories;
import com.baize.minespace.service.PostCategoriesService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 文章分类关联表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/post-categories")
public class PostCategoriesController {
    @Autowired
    private PostCategoriesService postCategoriesService;

    @ApiModelProperty("新增文章分类关联表")
    @ApiOperation(value = "新增文章分类关联表", notes = "新增文章分类关联表")
    @PostMapping("add")
    public Result<Boolean> addPostCategories(@RequestBody PostCategories postCategories){
        return Result.success(postCategoriesService.save(postCategories));
    }

    @ApiModelProperty("删除文章分类关联表")
    @ApiOperation(value = "删除文章分类关联表", notes = "删除文章分类关联表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deletePostCategories(@PathVariable(value = "id") Integer id) {
        return Result.success(postCategoriesService.removeById(id));
    }

    @ApiModelProperty("修改文章分类关联表")
    @ApiOperation(value = "修改文章分类关联表", notes = "修改文章分类关联表")
    @PostMapping("update")
    public Result<Boolean> updatePostCategories(@RequestBody PostCategories postCategories) {
        return Result.success(postCategoriesService.updateById(postCategories));
    }

    @ApiModelProperty("查询文章分类关联表")
    @GetMapping("select/{id}")
    public Result<PostCategories> selectPostCategories(@PathVariable(value = "id") Integer id) {
        return Result.success(postCategoriesService.getById(id));
    }

    @ApiModelProperty("分页查询文章分类关联表")
    @ApiOperation(value = "分页查询文章分类关联表", notes = "分页查询文章分类关联表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<PostCategories>> selectPostCategoriesPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody PostCategories postCategories
    ) {
        return postCategoriesService.selectPostCategoriesPage(rows, page, postCategories);
    }
}
